package com.fas.system.controller;

import com.fas.common.core.controller.BaseController;
import com.fas.common.core.domain.AjaxResult;
import com.fas.common.core.domain.entity.SysDept;
import com.fas.common.core.page.TableDataInfo;
import com.fas.common.utils.SecurityUtils;
import com.fas.system.domain.FasInspectionPlan;
import com.fas.system.service.IFasInspectionPlanService;
import com.fas.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 巡检计划 Controller
 *
 * @date 2022-07-04
 */
@Api(tags = "巡检计划")
@RestController
@RequestMapping("/system/inspection/plan")
public class FasInspectionPlanController extends BaseController {

    @Resource
    private IFasInspectionPlanService fasInspectionPlanService;

    @Resource
    private ISysDeptService deptService;

    @ApiOperation(value = "查询巡检计划列表")
    @GetMapping("/list")
    public TableDataInfo queryAll(FasInspectionPlan fasInspectionPlan, Integer pageNum, Integer pageSize){
        Long deptId = SecurityUtils.getDeptId();
        SysDept sysDept = deptService.selectDeptById(deptId);
        String deptType = sysDept.getDeptType();
        if (deptType.equals("1") || deptType.equals("2")){
            if(fasInspectionPlan.getDeptId() == null){
                fasInspectionPlan.setDeptId(deptId.intValue());
            }
        }
        startPage();
        return getDataTable(fasInspectionPlanService.queryAll(fasInspectionPlan));
    }

    @ApiOperation(value = "查询巡检计划详细信息")
    @GetMapping("/findById/{id}")
    public AjaxResult findById(@PathVariable Integer id){
        return AjaxResult.success(fasInspectionPlanService.findById(id));
    }

    @ApiOperation(value = "新增巡检计划")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FasInspectionPlan fasInspectionPlan){
        Long deptId = SecurityUtils.getDeptId();
        fasInspectionPlan.setDeptId(deptId.intValue());
        return toAjax(fasInspectionPlanService.insertFasInspectionPlan(fasInspectionPlan));
    }

    @ApiOperation(value = "修改巡检计划")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FasInspectionPlan fasInspectionPlan){
        return toAjax(fasInspectionPlanService.updateFasInspectionPlan(fasInspectionPlan));
    }

    @ApiOperation(value = "删除巡检计划")
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestParam("ids") Integer[] ids,@RequestParam("lineIds") Long[] lineIds){
        return toAjax(fasInspectionPlanService.deleteFasInspectionPlan(ids,lineIds));
    }

    @ApiOperation(value = "查询为空的巡检路线")
    @GetMapping("/selectNullLine")
    public TableDataInfo selectNullLine(@RequestParam(required = true) Integer cooperationCompanyId){
        return getDataTable(fasInspectionPlanService.selectNullLine(getDeptId(),cooperationCompanyId));
    }

}
